package com.ygh.controller;


import com.ygh.pojo.Notice;
import com.ygh.service.AdminNoticeService;
import com.ygh.vo.PageResult;
import com.ygh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/notice")
public class AdminNoticeController {
    @Autowired
    private AdminNoticeService adminNoticeService;

    @GetMapping("/getNoticeList")
   public SysResult getNoticeList(PageResult pageResult){
        pageResult=adminNoticeService.findNoticeList(pageResult);
        return SysResult.success(pageResult);
    }
    @GetMapping("/vip/getTitle")
    public SysResult getTitle(){
        List<Notice> list =adminNoticeService.findTitleList();
        return SysResult.success(list);
    }
    @GetMapping("/list")
    public List<Notice> list(){
        return adminNoticeService.findAll();
    }
    @PostMapping("/saveNotice")
    public SysResult saveNotice(@RequestBody Notice notice){
        adminNoticeService.saveNotice(notice);
        return SysResult.success();
    }
    @DeleteMapping("/deleteNotice/{id}")
    public SysResult deleteNotice(@PathVariable Integer id){
        adminNoticeService.deleteNotice(id);
        return SysResult.success();
    }
/*
     this.$http.put("/notice/updateNotice", this.addNoticeForm)
*/
    @PutMapping("/updateNotice")
    public SysResult updateNotice(@RequestBody Notice notice){
        adminNoticeService.updateNotice(notice);
        return SysResult.success();
    }
}
